<template>
  <view class="index">
    <view class="jtop">
      <view class="status_bar"><!-- 这里是状态栏 --></view>
      <view class="jtop_l" @tap="navigateBack"
        ><image src="../../static/img/ic_back.png"></image
      ></view>
      <view class="jtop_c">选择人员</view>
      <view class="jtop_r" @tap="jsave()">确定</view>
    </view>
    <view class="tophr"></view>
    <!-- <uni-search-bar placeholder="搜索" @confirm="search" class="ss" bgColor="#ffffff"></uni-search-bar> -->

    <!-- 	<view class="dus_box">
				<image src="../../static/img/index/new/ic_phone_blue.png" class="dus_box_s" @click="pc(item.mobile)"></image>
				
				<view class="dus_box_tx">
					<image :src="item.avatar" class="" @tap="tel_more(item.id,item.realname,item.duty,item.mobile,item.gender,item.email,item.avatar)"></image>
					
					<image :src="mrtx"  v-show="!item.actived" @tap="tel_more(item.id,item.realname,item.duty,item.mobile,item.gender,item.email,item.avatar)"></image>
					<text class="" v-show="!item.actived">未注册</text>
				</view>
				
				<view class="dus_box_l"  @tap="tel_more(item.id,item.realname,item.duty,item.mobile,item.gender,item.email,item.avatar)">
					<text class="dus_box_lt">{{item.realname}}</text>
					<text class="dus_box_lf">{{item.duty}}</text>
				</view>
			</view> -->

    <view class="dus_boxs">
      <view
        class="dus_box"
        @click="pc(index)"
        v-for="(item, index) in items"
        :key="item.id"
      >
        <image
          :src="
            item.jqedit == true
              ? '../../static/img/doc/ic_check_press.png'
              : '../../static/img/doc/ic_check_normal.png'
          "
          class="dus_box_s "
        ></image>

        <image
          :src="item.avatar ? item.avatar : mrtx"
          class="dus_box_tx"
        ></image>

        <view class="dus_box_l">
          <text class="dus_box_lt">{{
            item.name ? item.name : item.userInfoResponse.realName
          }}</text>
          <text class="dus_box_lf">{{ item.duty }}</text>
        </view>
      </view>
    </view>

    <view class="dttf"> 共{{ items.length }}人 </view>

    <!-- 	<view class="dus_tl">
			S
		</view>
		 -->
    <!-- <view class="dus_boxs">
			<view class="dus_box">
				<image src="../../static/img/doc/ic_check_press.png"  class="dus_box_s dus_box_sx"></image>
				<image src="../../static/img/jhead_portrait.png" class="dus_box_tx" ></image>
				<view class="dus_box_l">
					<text class="dus_box_lt">宋旋</text>
					<text class="dus_box_lf">首席搬砖工</text>
				</view>
			</view>
		</view>
		 -->
    <!-- 	<view class="dus_tl">
			X
		</view> -->

    <!-- 		<view class="dus_boxs">
			<view class="dus_box">
				<image src="../../static/img/doc/ic_check_press.png"  class="dus_box_s"></image>
				<image src="../../static/img/jhead_portrait.png" class="dus_box_tx" ></image>
				<view class="dus_box_l">
					<text class="dus_box_lt">小布衣</text>
					<text class="dus_box_lf">底层搬砖工</text>
				</view>
			</view>
			<view class="dus_box">
				<image src="../../static/img/doc/ic_check_normal.png"  class="dus_box_s"></image>
				<image src="../../static/img/jhead_portrait.png" class="dus_box_tx" ></image>
				<view class="dus_box_l">
					<text class="dus_box_lt">小布衣</text>
					<text class="dus_box_lf">底层搬砖工</text>
				</view>
			</view>
		</view> -->
  </view>
</template>

<script>
import request from '@/common/request.js';
import { mapState } from 'vuex';

export default {
  computed: mapState(['forcedLogin', 'hasLogin', 'userName']),
  data() {
    return {
      repeat_click: true,
      show_xl: false,
      js: '',
      ky: true,
      id: '',
      jsid: '',
      items: [],
      dyid: '',
      mrtx: '../../static/img/Default_avatar.png',
      jqeditry: [],
      jqeditrytx: [],
      jedittx: false,
    };
  },
  onLoad(e) {
    this.id = e.id;
    this.jsid = e.jsid;
    this.corpId = uni.getStorageSync('token_type').corp_id;

    var jd = {
      page: 1,
      size: 1000000,
    };

    if (e) {
      jd.key = e;
    }

    request({
      // ${uni.getStorageSync("user").corp_id}

      url: `/ucenter/corp-user/user/list`,

      data: {
        corpId: uni.getStorageSync('user').corpBaseInfoResponse.id,
		projectId: uni.getStorageSync('dqfull_name').id,
      },

      // url: `/biz/addr-book/page`,

      // data: jd,

      method: 'GET',
      success: openIdRes => {
        console.log('users:', openIdRes);

        var cc = openIdRes.data.data;
        for (var i = 0; i < cc.length; i++) {
          cc[i].jqedit = false;
        }

        this.items = cc;
      },
      fail: () => {
        this.repeat_click = true;
        uni.showToast({
          title: '服务器开小差，请稍后~',
          icon: 'none',
        });
        return false;
      },
    });
  },

  methods: {
    pc(e) {
      console.log(e);
      this.items[e]['jqedit'] = !this.items[e]['jqedit'];

      var bh = this.jqeditry.indexOf(this.items[e].userInfoResponse.id);

      if (bh == -1) {
        this.jqeditry.unshift(this.items[e].userInfoResponse.id);

        if (this.items[e].avatar) {
          this.jqeditrytx.unshift(this.items[e].avatar);
        } else {
          this.jqeditrytx.unshift('../../static/img/Default_avatar.png');
        }
      } else {
        var ax = this.jqeditry;
        ax.splice(bh, 1);
        this.jqeditry = ax;

        var axtx = this.jqeditrytx;
        axtx.splice(bh, 1);
        this.jqeditrytx = axtx;
      }

      console.log(this.jqeditry);
      console.log(this.jqeditrytx);

      uni.setStorageSync('jqeditry', this.jqeditry);
      uni.setStorageSync('jqeditrytx', this.jqeditrytx);
    },

    jsave() {
      if (!this.repeat_click) {
        return;
      }
      this.repeat_click = false;

      request({
        url: `/ucenter/project-user`,
        data: {
          projectId: uni.getStorageSync('dqfull_name').id,
          userIds: this.jqeditry,
          roleId: parseInt(this.jsid),
        },

        method: 'POST',
        success: openIdRes => {
          console.log(openIdRes);
          if (openIdRes.data.success == true) {
            wx.showToast({
              title: '添加成功',
              icon: 'none',
              duration: 1000,
              success: function() {
                setTimeout(function() {
                  uni.removeStorageSync('jqeditry');
                  uni.removeStorageSync('jqeditrytx');
                  uni.navigateBack();
                }, 1500);
              },
            });

            // uni.navigateBack()
          } else {
            this.repeat_click = true;
            uni.showToast({
              title: openIdRes.data.msg,
              icon: 'none',
            });
            this.isLoading = false;
          }
        },
        fail: () => {
          this.repeat_click = true;
          uni.showToast({
            title: '服务器开小差，请稍后~',
            icon: 'none',
          });
          return false;
        },
      });
    },

    navigateBack() {
      if (!this.jedittx) {
        uni.removeStorageSync('jqeditry');
        uni.removeStorageSync('jqeditrytx');
      }
      uni.navigateBack();
    },
  },
};
</script>

<style>
.tophr {
  width: 100%;
  height: 88rpx;
}
.uni-searchbar {
  box-shadow: none;
}
.tc {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10000;
  display: block;
}
.dus {
  width: 100%;
  height: 90rpx;
  display: block;
  float: left;
  border: 1px solid #dddddd;
  border-left: 0;
  border-right: 0;
  background: #ffffff;
}
.dusl {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
  margin: 21rpx 22rpx 21rpx 30rpx;
}
.dusc {
  width: auto;
  height: 42rpx;
  font-size: 34rpx;
  line-height: 42rpx;
  color: #000000;
  display: block;
  float: left;
  margin: 24rpx 0;
}
.dusr {
  width: 16rpx;
  height: 25rpx;
  display: block;
  float: right;
  margin: 33rpx 30rpx 0 0;
}
.dus_t {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  font-size: 24rpx;
  line-height: 32rpx;
  color: #999999;
  border-bottom: 1px solid #dddddd;
  padding: 20rpx 30rpx;
  box-sizing: border-box;
}
.dus_tl {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  font-size: 24rpx;
  line-height: 32rpx;
  color: #999999;
  padding: 4rpx 30rpx;
  box-sizing: border-box;
}
.dus_boxs {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  border: 1px solid #dddddd;
  border-left: 0;
  border-right: 0;
  background: #ffffff;
}
.dus_box {
  width: 720rpx;
  margin: 0 0 0 30rpx;
  height: 120rpx;
  display: block;
  float: left;
  background: #ffffff;
  border-bottom: 1px solid #dddddd;
}
.dus_boxs .dus_box:last-child {
  border: 0;
}
.dus_box_s {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
  margin: 36rpx 30rpx 0 0;
}
.dus_box_s {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
  margin: 36rpx 30rpx 0 0;
}
.dus_box_tx {
  width: 84rpx;
  height: 84rpx;
  display: block;
  float: left;
  margin: 18rpx 20rpx 0rpx 0;
}
.dus_box_l {
  width: 500rpx;
  height: auto;
  display: block;
  float: left;
  margin: 0rpx 0 0rpx 0;
}
.dus_box_lt {
  width: 100%;
  height: 42rpx;
  display: block;
  float: left;
  margin: 18rpx 0 10rpx 0;
  font-size: 34rpx;
  line-height: 42rpx;
  color: #000000;
}
.dus_box_lt2 {
  width: 100%;
  height: 42rpx;
  display: block;
  float: left;
  margin: 45rpx 0 10rpx 0;
  font-size: 34rpx;
  line-height: 42rpx;
  color: #000000;
}
.dus_box_lf {
  width: 100%;
  height: 32rpx;
  display: block;
  float: left;
  margin: 0rpx 0 0rpx 0;
  font-size: 24rpx;
  line-height: 32rpx;
  color: #999999;
}
.dus_box_sx {
  opacity: 0.5;
}

.dcf {
  width: 100%;
  height: 120rpx;
  display: block;
  float: left;
  position: fixed;
  left: 0;
  bottom: 0;
  background: #ffffff;
  box-shadow: inset 0px 1px 0px #dddddd;
  z-index: 1000;
  padding: 18rpx 30rpx;
  box-sizing: border-box;
}
.dcf_tx {
  width: 84rpx;
  height: 84rpx;
  display: block;
  float: left;
  margin: 0rpx 20rpx 0rpx 0;
}
.dcf_t {
  width: auto;
  height: 84rpx;
  line-height: 84rpx;
  display: block;
  float: right;
  margin: 0rpx 0rpx 0rpx 0;
  font-size: 36rpx;
  color: #256aff;
}
.dttf {
  width: 100%;
  height: 84rpx;
  line-height: 84rpx;
  display: block;
  float: left;
  position: fixed;
  left: 0;
  bottom: 0;
  margin: 0rpx 0rpx 0rpx 0;
  font-size: 24rpx;
  color: #999999;
  text-align: center;
}

.index {
  background: rgb(242, 242, 242);
  width: 100%;
  height: auto;
}
.jtop {
  width: 100%;
  height: 88rpx;
  background: #ffffff;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
}
.jtop_l {
  width: auto;
  height: 88rpx;
  display: block;
  float: left;
  font-size: 32rpx;
  color: #000000;
  line-height: 88rpx;
  margin: 0 0 0 30rpx;
}
.jtop_l image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
  margin: 20rpx 0 20rpx 0;
}
.jtop_r {
  width: auto;
  height: 88rpx;
  display: block;
  float: right;
  margin: 0rpx 20rpx 0 0;
  line-height: 88rpx;
  font-size: 32rpx;
  color: #000000;
  color: #256aff;
}
.jtop_r image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
}
.jtop_c {
  width: 70%;
  height: 48rpx;
  line-height: 48rpx;
  display: block;
  float: left;
  position: fixed;
  top: 20rpx;
  left: 15%;
  text-align: center;
  font-size: 36rpx;
  color: #000000;
}
.jtop_c image {
  width: 36rpx;
  height: 36rpx;
  display: inline-block;
  float: none;
  margin-bottom: -5rpx;
  margin-left: 5rpx;
}
.jtop_b {
  width: 100%;
  height: auto;
  background: #ffffff;
  position: fixed;
  top: 88rpx;
  left: 0;
  z-index: 1001;
}

.uni-searchbar {
  background: rgb(242, 242, 242);
}
.index .uni-searchbar__box {
  background: #ffffff !important;
}
</style>
